<?php
header("Content-type: text/html; charset=utf-8");
include_once( 'config.php' );
$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD); 
mysql_select_db(DB_NAME,$con);
mysql_query("SET NAMES utf8");
//print_r($_POST);
$screen_name = $_POST['screen_name'];
$user_id = $_POST['user_id'];
$cate = $_POST['cate'];
$sns = $_POST['sns'];

$num1 = 0;$num2 = 0;$num3 = 0;
for($i=0;$i<count($user_id);$i++){ 
    if($sns[$i] == 'renren'){
        $cai_table = 'cai_renren_fensi';
    }elseif($sns[$i] == 'weibo'){
        $cai_table = 'cai_weibo_fensi';
    }
    $sql="select * from ".$cai_table." where user_id='".trim($user_id[$i])."'"; 
    $result=@mysql_query($sql);
    $row = @mysql_fetch_array($result, MYSQL_ASSOC);
    if (!@mysql_num_rows($result)){
        $sql2="INSERT INTO ".$cai_table." (`id`, `user_id`, `screen_name` , `cate`,`sns` ) VALUES (NULL,'".$user_id[$i]."','".$screen_name[$i]."','".$cate[$i]."','".$sns[$i]."');";
        if(@mysql_query($sql2)){
            //echo '成功插入';
            $num1 = $num1 +1;
        }else{
            //echo '插入失败';
            $num3 = $num3 +1;
        }  
    }else{
        $num2 = $num2 +1;
    } 
}
$array=array(0=>$num1,1=>$num2,2=>$num3);
echo json_encode($array);
?>